<?php 

include_once( TOptions::serverCoreLibFile( 'TAppTable.php' ) );

/***************************************************************************
* TFire
***************************************************************************/
class TFire extends TAppTable
{
    var $tableName                           = TOptions::tabEvent;
    
    var $fldRecordId                         = 'event_id';
    var $fldGlobalId                         = 'global_record_id';
    var $fldRecordCreationTime               = 'creation_time';
    
    var $jsonFields                          = '{
          "event_id":{"type":"integer","no_insert":"1","no_update":"1","alias":"i"}
        , "creation_time":{"type":"datetime","no_insert":"1","no_update":"1"}
        , "update_time":{"type":"timestamp","no_insert":"1","no_update":"1"}
        , "global_record_id":{"type":"bigint","no_insert":"1","no_update":"1","alias":"g"}
        , "event_type_code":{"type":"bigint"}
        , "event_date":{"type":"date"}
        , "fabula":{"type":"text"}
        , "region_id":{"type":"string"}
    }';
    
    /***********************************************************************
    * getAllFires
    ***********************************************************************/
    public function getAllFires( $aSortField = '' )
    {
        $conditions   = 'event_type_code=11540';
        $selectFields = '**';
        if ( !empty( $aSortField ) )
        {
            $aSortField = 'order by '.$aSortField.' asc';
        }
        
        $Result = $this->selectRecords( $conditions, $selectFields, 'event_id', $aSortField );
        return $Result;
    }
    
    /***********************************************************************
    * getSortedByRegion
    ***********************************************************************/
    public function getSortedByRegion()
    {
        $fields = $this->getSelectFields( '**' );
        $order  = 'order by regionName asc, event_date desc';
        
        $sql  = 'select '.$fields.', '.TOptions::tabRegion.'.value as regionName from '.$this->tableName;
        $sql .= ' left join '.TOptions::tabRegion.' on region_id = code where event_type_code=11540';
        $sql .= ' '.$order;

//echo $sql;
        $Result = $this->select( $sql, 'event_id' );
        return $Result;
    }
    
    /***********************************************************************
    * getSortedByDate
    ***********************************************************************/
    public function getSortedByDate()
    {
    
    }
    
    /***********************************************************************
    * getFireInfo
    ***********************************************************************/
    public function getFireInfo( $aEventId )
    {
        $Result = $this->selectRecord( $aEventId );
        return $Result;
    }
}